## Figure E.1: Relationship between Different Corporate Donation Types and Lobbying
# Expenses, 2008-2018:: --------------------------------------------------------

## Instructions ----------------------------------------------------------------
# Step 1: Adjust MAIN_DIR to main folder
# Step 2: Adjust DATA_DIR to where data is is located
# Step 3: Adjust FIG_DIR to where output folder is
# Step 4: Run entire script
## setup -----------------------------------------------------------------------

# clean slate
rm(list = ls())

library(tidyverse)

# set directory
MAIN_DIR <- "C:/Users/js.egb/Dropbox/campaign-lobby-paper/replication_package"

# set data folder
DATA_DIR <-  paste(MAIN_DIR, "/data/", sep = "")

# set output folder
FIG_DIR <- paste(MAIN_DIR, "/output/", sep = "")

# file to be read in
file_in1 <- paste0(DATA_DIR, "d_final_20210127.RData") # file to be input

### 3. Scatter Plot A La Ansolabehere et al 2002:
load(file_in1)


# aggregate data
ast_plot <- d_final %>% group_by(gvkey) %>%
  summarise(don_pac = sum(don_pac, na.rm = TRUE), 
            don_all = sum(don_tot, na.rm = TRUE),
            don_emp = sum(don_emp, na.rm = TRUE),
            don_ceo = sum(don_ceo, na.rm = TRUE),
            don_gov = sum(don_gov, na.rm = TRUE),
            lob = sum(lobbying_amount, na.rm = TRUE)) %>%
  filter(don_pac >= 0 & lob >= 0)


pdf(paste0(FIG_DIR, "/figure_e1.pdf"), width = 22, height = 16) # open graphics device
par(mfrow = c(2,2), mar = c(8,5.5,5,0), las = 1, cex.axis = 1.8, cex.lab = 2.2, cex.main = 2.6)


# ANY DONATIONS
plot(log(ast_plot$don_all+1), log(ast_plot$lob+1), pch = 16,col = "darkgrey", las = 0.8, font.lab = 2, axes = FALSE,
     main = "All Donations",  xlim = c(0, 18), ylim = c(0, 23),
     xlab = "", ylab = "")
grid(col = "lightgrey", lty = "solid")
points(log(ast_plot$don_all+1), log(ast_plot$lob+1), pch = 16,col = "darkgrey", las = 0.8, font.lab = 2, 
       main = "")  
text(x = 2.75, y =  21, labels = expression(paste(beta, " = 0.61, R2 = 0.30")), cex = 1.75) # R2 = 0.195
axis(1, at = seq(0, 24, 5), labels = seq(0, 24, 5))
axis(2, at = seq(0, 25, 5), labels = seq(0, 25, 5))
clip(2,18, 0, 22)
abline(lm(log(ast_plot$lob[ast_plot$lob>0 & ast_plot$don_all>0]) ~ log(ast_plot$don_all[ast_plot$lob>0 & ast_plot$don_all>0])), 
       col = "black", lwd = 4, )
title(xlab = "Log Total Donations, in US$", line = 3.5)
title(ylab = "Log Total Lobbying, in US$", line = 3.5)


# CEO DONATIONS
plot(log(ast_plot$don_ceo+1), log(ast_plot$lob+1), pch = 16,col = "darkgrey", las = 0.8, font.lab = 2, axes = FALSE,
     main = "Executive Donations",  xlim = c(0, 18), ylim = c(0, 23),
     xlab = "", ylab = "")
grid(col = "lightgrey", lty = "solid")
points(log(ast_plot$don_ceo+1), log(ast_plot$lob+1), pch = 16,col = "darkgrey", las = 0.8, font.lab = 2, 
       main = "")  
text(x = 2.75, y =  21, labels = expression(paste(beta, " = 0.57, R2 = 0.15")), cex = 1.75) # R2 = 0.195
axis(1, at = seq(0, 24, 5), labels = seq(0, 24, 5))
axis(2, at = seq(0, 25, 5), labels = seq(0, 25, 5))
clip(2,18, 0, 22)
abline(lm(log(ast_plot$lob[ast_plot$lob>0 & ast_plot$don_ceo>0]) ~ log(ast_plot$don_ceo[ast_plot$lob>0 & ast_plot$don_ceo>0])), 
       col = "black", lwd = 4, )
title(xlab = "Log Total Donations, in US$", line = 3.5)
title(ylab = "Log Total Lobbying, in US$", line = 3.5)

# EMP DONATIONS
plot(log(ast_plot$don_emp+1), log(ast_plot$lob+1), pch = 16,col = "darkgrey", las = 0.8, font.lab = 2, axes = FALSE,
     main = "Employee Donations",  xlim = c(0, 18), ylim = c(0, 23),
     xlab = "", ylab = "")
grid(col = "lightgrey", lty = "solid")
points(log(ast_plot$don_emp+1), log(ast_plot$lob+1), pch = 16,col = "darkgrey", las = 0.8, font.lab = 2, 
       main = "")  
text(x = 2.75, y =  21, labels = expression(paste(beta, " = 0.70, R2 = 0.23")), cex = 1.75) # R2 = 0.195
axis(1, at = seq(0, 24, 5), labels = seq(0, 24, 5))
axis(2, at = seq(0, 25, 5), labels = seq(0, 25, 5))
clip(2,18, 0, 22)
abline(lm(log(ast_plot$lob[ast_plot$lob>0 & ast_plot$don_emp>0]) ~ log(ast_plot$don_emp[ast_plot$lob>0 & ast_plot$don_emp>0])), 
       col = "black", lwd = 4, )
title(xlab = "Log Total Donations, in US$", line = 3.5)
title(ylab = "Log Total Lobbying, in US$", line = 3.5)


# GOV DONATIONS
plot(log(ast_plot$don_gov+1), log(ast_plot$lob+1), pch = 16,col = "darkgrey", las = 0.8, font.lab = 2, axes = FALSE,
     main = "Government Relations Donations",  xlim = c(0, 18), ylim = c(0, 23),
     xlab = "", ylab = "")
grid(col = "lightgrey", lty = "solid")
points(log(ast_plot$don_gov+1), log(ast_plot$lob+1), pch = 16,col = "darkgrey", las = 0.8, font.lab = 2, 
       main = "")  
text(x = 2.75, y =  21, labels = expression(paste(beta, " = 0.84, R2 = 0.21")), cex = 1.75) # R2 = 0.195
axis(1, at = seq(0, 24, 5), labels = seq(0, 24, 5))
axis(2, at = seq(0, 25, 5), labels = seq(0, 25, 5))
clip(2,18, 0, 22)
abline(lm(log(ast_plot$lob[ast_plot$lob>0 & ast_plot$don_gov>0]) ~ log(ast_plot$don_gov[ast_plot$lob>0 & ast_plot$don_gov>0])), 
       col = "black", lwd = 4, )
title(xlab = "Log Total Donations, in US$", line = 3.5)
title(ylab = "Log Total Lobbying, in US$", line = 3.5)
dev.off() # close graphics device
